<!--  -->
<template>
  <div>
    <flow :tableId="tableId" :flowPermission="flowPermission" :nodeConfig="nodeConfig" :directorMaxLevel="directorMaxLevel" :isTried="isTried" :isFlag="isFlag"></flow>
  </div>
</template>

<script>
  import { processGenerateKey, processDetail } from '../../../api/process';
  import flow from '../../../components/process/flow.vue';
  import { mapGetters, mapActions } from 'vuex';
  export default {
    components: {
      flow,
    },
    data() {
      return {
        opt: ['基础设置', '流程设计'],
        isTried: false,
        tipList: [],
        tipVisible: false,
        nowVal: 100,
        processConfig: {},
        nodeConfig: {},
        workFlowDef: {},
        flowPermission: [],
        directorMaxLevel: 0,
        dialogVisible: true,
        tableId: '',
        idx: 0,
        initData: {
          pkId: 'sid-start-node',
          nodeName: '开始节点',
          nodeType: '1',
          routerNodeCode: '',
          parentNode: '',
          organizeApproveRule: '',
          nodeApproveType: '',
          createUser: '',
          procNodeConditionList: [],
          childNode: null,
          primaryKey: '',
          processCode: '',
          parentNode: '',
          nextNode: '',
          routerNodeCode: -1,
          approveLevel: '',
        },
        isFlag: false,
      };
    },
    computed: {
      // ...mapGetters({
      // 	userInfo: 'getUserInfo'
      // })
    },
    watch: {},
    mounted() {},
    methods: {
      toReturn() {
        //window.location.href = ""
      },
      reErr(data) {
        if (data.childNode) {
          if (data.childNode.type == 1) {
            //审批人
            if (data.childNode.error) {
              this.tipList.push({
                name: data.childNode.nodeName,
                type: '审核人',
              });
            }
            this.reErr(data.childNode);
          } else if (data.childNode.type == 2) {
            if (data.childNode.error) {
              this.tipList.push({
                name: data.childNode.nodeName,
                type: '抄送人',
              });
            }
            this.reErr(data.childNode);
          } else if (data.childNode.type == 3) {
            this.reErr(data.childNode.childNode);
          } else if (data.childNode.type == 4) {
            this.reErr(data.childNode);
            for (var i = 0; i < data.childNode.conditionNodes.length; i++) {
              if (data.childNode.conditionNodes[i].error) {
                this.tipList.push({
                  name: data.childNode.conditionNodes[i].nodeName,
                  type: '条件',
                });
              }
              this.reErr(data.childNode.conditionNodes[i]);
            }
          }
        } else {
          data.childNode = null;
        }
      },
      async getInfo() {
        let processCode = this.$route.query.key;
        if (processCode) {
          let res = await processDetail({ processCode: processCode });
          if (res.key) {
            this.isFlag = true;
            this.nodeConfig = JSON.parse(res.key);
            console.log('nodeConfig:', this.nodeConfig);
          } else {
            this.isFlag = false;
            let primaryKeyList = await processGenerateKey({ nodeType: 1 });
            primaryKeyList = primaryKeyList.rows;
            this.initData.processCode = processCode;
            this.initData.primaryKey = primaryKeyList[0].primaryKey;
            // this.initData.nodeName = this.userInfo.loginUserInfoResponseVos.userName
            this.initData.nodeName = '初始节点';
            this.nodeConfig = this.initData;
          }
        }
      },
      saveSet() {
        this.isTried = true;
        this.tipList = [];
        this.reErr(this.nodeConfig);
        if (this.tipList.length != 0) {
          this.tipVisible = true;
          // return;
        }
        this.processConfig.flowPermission = this.flowPermission;
      },
      zoomSize(type) {
        if (type == 1) {
          if (this.nowVal == 50) {
            return;
          }
          this.nowVal -= 10;
        } else {
          if (this.nowVal == 300) {
            return;
          }
          this.nowVal += 10;
        }
      },
    },
  };
</script>

<style lang="scss" scoped>
  // @import "../../../../assets/css/workflow.css";
  .error-modal-list {
    width: 455px;
  }
</style>
